package com.bcmusic.point.controller;

import com.bcmusic.point.pojo.UserMcLog;
import com.bcmusic.point.service.UserMcLogService;
import com.github.pagehelper.PageInfo;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:admin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/userMcLog")
@CrossOrigin
public class UserMcLogController {

    @Autowired
    private UserMcLogService userMcLogService;

    /***
     * UserMcLog分页条件搜索实现
     * @param userMcLog
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false)  UserMcLog userMcLog, @PathVariable  int page, @PathVariable  int size){
        //调用UserMcLogService实现分页条件查询UserMcLog
        PageInfo<UserMcLog> pageInfo = userMcLogService.findPage(userMcLog, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * UserMcLog分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用UserMcLogService实现分页查询UserMcLog
        PageInfo<UserMcLog> pageInfo = userMcLogService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param userMcLog
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<UserMcLog>> findList(@RequestBody(required = false)  UserMcLog userMcLog){
        //调用UserMcLogService实现条件查询UserMcLog
        List<UserMcLog> list = userMcLogService.findList(userMcLog);
        return new Result<List<UserMcLog>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Long id){
        //调用UserMcLogService实现根据主键删除
        userMcLogService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改UserMcLog数据
     * @param userMcLog
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody  UserMcLog userMcLog,@PathVariable Long id){
        //设置主键值
        userMcLog.setMcLogId(id);
        //调用UserMcLogService实现修改UserMcLog
        userMcLogService.update(userMcLog);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增UserMcLog数据
     * @param userMcLog
     * @return
     */
    @PostMapping
    public Result add(@RequestBody   UserMcLog userMcLog){
        //调用UserMcLogService实现添加UserMcLog
        userMcLogService.add(userMcLog);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询UserMcLog数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<UserMcLog> findById(@PathVariable Long id){
        //调用UserMcLogService实现根据主键查询UserMcLog
        UserMcLog userMcLog = userMcLogService.findById(id);
        return new Result<UserMcLog>(true,StatusCode.OK,"查询成功",userMcLog);
    }

    /***
     * 查询UserMcLog全部数据
     * @return
     */
    @GetMapping
    public Result<List<UserMcLog>> findAll(){
        //调用UserMcLogService实现查询所有UserMcLog
        List<UserMcLog> list = userMcLogService.findAll();
        return new Result<List<UserMcLog>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
